package com.fizzkai.p2p.bussness.service.impl;

import com.fizzkai.p2p.bussness.domain.PlatformBankInfo;
import com.fizzkai.p2p.bussness.mapper.PlatformBankInfoMapper;
import com.fizzkai.p2p.bussness.query.PlatformBankInfoQuery;
import com.fizzkai.p2p.bussness.service.IPlatformBankInfoService;
import com.fizzkai.p2p.core.query.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service@Transactional
public class PlatformBankInfoServiceImpl implements IPlatformBankInfoService {

    @Autowired
    private PlatformBankInfoMapper bankInfoMapper;


    @Override
    public int save(PlatformBankInfo entity) {
        return bankInfoMapper.insert(entity);
    }

    @Override
    public int update(PlatformBankInfo entity) {
        return bankInfoMapper.updateByPrimaryKey(entity);
    }

    @Override
    public PlatformBankInfo get(Long id) {
        return bankInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<PlatformBankInfo> query(QueryObject qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        List<PlatformBankInfo> list = bankInfoMapper.queryList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public int saveOrUpdate(PlatformBankInfo bankInfo) {
        int row;
        if (bankInfo.getId() == null) {
            row = bankInfoMapper.insert(bankInfo);
        } else {
            row = bankInfoMapper.updateByPrimaryKey(bankInfo);
        }
        return row;
    }

    @Override
    public List<PlatformBankInfo> list() {
        return bankInfoMapper.queryList(new PlatformBankInfoQuery());
    }
}
